package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ExamManagement;
import cn.wolfcode.crm.query.ExamManagementQueryObject;
import cn.wolfcode.crm.service.IExamManagementService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("exam")
public class ExamManagementController {

    @Autowired
    private IExamManagementService examManagementService;

    @RequestMapping("view")
    public String view(){
        return "/exam/exam";
    }

    @RequestMapping("pass")
    @ResponseBody
    @RequiresPermissions(value = {"exam:pass", "考试审核"}, logical = Logical.OR)
    public JSONResult pass(Long id) {
        try {
            examManagementService.pass(id);
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }
    @RequestMapping("refuse")
    @ResponseBody
    @RequiresPermissions(value = {"exam:refuse", "考试不通过"}, logical = Logical.OR)
    public JSONResult refuse(Long id) {
        try {
            examManagementService.refuse(id);
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }
    @RequestMapping("save")
    @ResponseBody
    @RequiresPermissions(value = {"exam:save", "考试登记"}, logical = Logical.OR)
    public JSONResult save(ExamManagement examManagement) {
        try {
            examManagementService.save(examManagement);
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }

    @ResponseBody
    @RequestMapping("query")
    public PageResult query(ExamManagementQueryObject qo) {
        return examManagementService.query(qo);
    }


    @RequestMapping("selectAll")
    @ResponseBody
    public List<ExamManagement> selectAll() {
        return examManagementService.selectAll();
    }


}
